*/
namespace Wikimedia\Rdbms;
- use DBError;
- use DBAccessError;
- use DBTransactionError;
- use DBExpectedError;
use Exception;
use InvalidArgumentException;
* If a DB_REPLICA connection has been opened already, then wait immediately.
* Otherwise sets a variable telling it to wait if such a connection is opened.
*
+ * This only applies to connections to the generic replica DB for this request.
+ * If a timeout happens when waiting, then getLaggedReplicaMode()/laggedReplicaUsed()
+ * will return true.
+ *
* @param DBMasterPos|bool $pos Master position or false
*/
public function waitFor( $pos );
/**
* @note This method will trigger a DB connection if not yet done
* @param string|bool $domain Domain ID, or false for the current domain
- * @return bool Whether the generic connection for reads is highly "lagged"
+ * @return bool Whether the database for generic connections this request is highly "lagged"
*/
public function getLaggedReplicaMode( $domain = false );
/**
+ * Checks whether the database for generic connections this request was both:
+ * - a) Already choosen due to a prior connection attempt
+ * - b) Considered highly "lagged"
+ *
* @note This method will never cause a new DB connection
- * @return bool Whether any generic connection used for reads was highly "lagged"
+ * @return bool
*/
public function laggedReplicaUsed();
use EmptyBagOStuff;
use WANObjectCache;
use ArrayUtils;
- use DBError;
- use DBAccessError;
- use DBExpectedError;
- use DBUnexpectedError;
- use DBTransactionError;
- use DBTransactionSizeError;
- use DBConnectionError;
use InvalidArgumentException;
use RuntimeException;
use Exception;
# Replica DB connection successful.
# Wait for the session master pos for a short time.
if ( $this->mWaitForPos && $i > 0 ) {
- $this->doWait( $i );
+ # When LoadBalancer::waitFor() set mWaitForPos, the wait will happen here.
+ # Be sure to update laggedReplicaMode accordingly for consistency.
+ if ( !$this->doWait( $i ) ) {
+ $laggedReplicaMode = true;
+ }
}
if ( $this->mReadIndex <= 0 && $this->mLoads[$i] > 0 && $group === false ) {
$this->mReadIndex = $i;
}
}
} finally {
- // Restore the older position if it was higher
+ // Restore the older position if it was higher since this is used for lag-protection
$this->setWaitForPositionIfHigher( $oldPos );
}
}
$ok = true; // no applicable loads
}
} finally {
- // Restore the older position if it was higher
- $this->setWaitForPositionIfHigher( $oldPos );
+ # Restore the old position, as this is not used for lag-protection but for throttling
+ $this->mWaitForPos = $oldPos;
}
return $ok;
}
}
} finally {
- // Restore the older position if it was higher
- $this->setWaitForPositionIfHigher( $oldPos );
+ # Restore the old position, as this is not used for lag-protection but for throttling
+ $this->mWaitForPos = $oldPos;
}
return $ok;